Calendar All Tests
Current file: /home/estudydev/workspace/eStudy_svn/web/ressourcen/classes/class.ressourcendb.inc.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 16
0.00 %0.00%
0.00% 0 / 202
 
RessourcenDB
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 16
0.00 %0.00%
0.00% 0 / 202
 public function __construct($fileManager = NULL)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 2
 public function setFileManager($filemanager)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 2
 public static function getVisibilityConstraintSQL()
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 18
 public function getSubFolder($pFolder)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 27
 public static function saveFolderState($folder)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 11
 private function getFileObject($dbObject)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 16
 private function getFolderObject($folderDB)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 11
 public function getFiles($folderID, $sortString = 'create_time', $desc = true)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 27
 public function getNewestFiles($limit = 20)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 15
 public function getMostRatedFiles($limit = 20)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 15
 public function getFileByID($fileID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 10
 public function getFolderByID($folderID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 8
 public function getUserCourses($userID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 12
 public function countSubElements($folderID, $subFolders = true)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 16
 public function getCourseShortNameByID($courseID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 3
 public function logResourceDownload($resourceID)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 9


       1                 : <?php                                                                                                          
       2                 : /*--------------------------------------------------------------------------+                                  
       3                 : This file is part of eStudy.                                                                                   
       4                 : ressourcen/classes/filemanager/class.ressourcendb.inc.php                                                      
       5                 : - Modulgruppe:  File Manager                                                                                   
       6                 : - Beschreibung: Klasse zur Datenbankanbindung                                                                  
       7                 : - Version:      0.4, 08.01.08                                                                                  
       8                 : - Autor(en):    Tobias Wild <tobias.wild@mni.fh-giessen.de>                                                    
       9                 : +---------------------------------------------------------------------------+                                  
      10                 : This program is free software; you can redistribute it and/or                                                  
      11                 : modify it under the terms of the GNU General Public License                                                    
      12                 : as published by the Free Software Foundation; either version 2                                                 
      13                 : of the License, or any later version.                                                                          
      14                 : +---------------------------------------------------------------------------+                                  
      15                 : This program is distributed in the hope that it will be useful,                                                
      16                 : but WITHOUT ANY WARRANTY; without even the implied warranty of                                                 
      17                 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                  
      18                 : GNU General Public License for more details.                                                                   
      19                 : You should have received a copy of the GNU General Public License                                              
      20                 : along with this program; if not, write to the Free Software                                                    
      21                 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                                    
      22                 : +--------------------------------------------------------------------------*/                                  
      23                 :                                                                                                                
      24                 : if (!defined("PATH_TO_ROOT")) {                                                                                
      25                 :     define("PATH_TO_ROOT", "../../");                                                                          
      26                 : }                                                                                                              
      27                 :                                                                                                                
      28                 : class RessourcenDB {                                                                                           
      29                 :     private $fileManager = null;                                                                               
      30                 :                                                                                                                
      31                 :     public function __construct($fileManager = null) {                                                         
      32               0 :         $this->fileManager = $fileManager;                                                                     
      33               0 :     }                                                                                                          
      34                 :                                                                                                                
      35                 :     public function setFileManager($filemanager) {                                                             
      36               0 :         $this->fileManager = $filemanager;                                                                     
      37               0 :     }                                                                                                          
      38                 :                                                                                                                
      39                 :     public static function getVisibilityConstraintSQL() {                                                      
      40               0 :         global $db, $settings;                                                                                 
      41               0 :         $time = Data::toMysql(time());                                                                         
      42               0 :         $userid = Data::toMysql($_SESSION["userid"]);                                                          
      43               0 :         $sqlAdd = "";                                                                                          
      44               0 :         if ($_SESSION['usergroup'] == STUDENT                                                                  
      45               0 :         || $_SESSION['usergroup'] == ALUMNUS                                                                   
      46               0 :         || $_SESSION['usergroup'] == SCHUELER                                                                  
      47               0 :         || $_SESSION['usergroup'] == GAST                                                                      
      48               0 :         || $_SESSION["usergroup"] == SEKRETARIAT) {                                                            
      49                 :             // Hier darf kein visible_type eingeschraenkt werden,                                              
      50                 :             // da sonst die Einzeluser-Berechtigung nicht mehr funktioniert !!!                                
      51               0 :             $sqlAdd = "AND ((filelist.userID='".$userid."' OR (start_time<'                                    
      52               0 :                 $time' AND end_time>'$time' AND visible_type=1))";                                             
      53               0 :             if (isset($_SESSION["assistent"])) // TUTOR                                                        
      54               0 :             $sqlAdd = "AND ((visible_type<='2' OR filelist.userID='".$userid."')";                             
      55               0 :             $visibleFiles = $db->get_col("SELECT fileID FROM filevisible WHERE userID='".$userid."'");         
      56               0 :             if ($db->num_rows) $sqlAdd.= " OR fileID IN (".implode(",", $visibleFiles) .")";                   
      57               0 :             $sqlAdd.= ")";                                                                                     
      58               0 :         }                                                                                                      
      59               0 :         return $sqlAdd;                                                                                        
      60                 :     }                                                                                                          
      61                 :                                                                                                                
      62                 :     public function getSubFolder($pFolder) {                                                                   
      63               0 :         global $db;                                                                                            
      64               0 :         $sqlAdd = self::getVisibilityConstraintSQL();                                                          
      65               0 :         $folderID = Data::toMysql($pFolder->getID());                                                          
      66                 :                                                                                                                
      67               0 :         if ($folderID == 0) {                                                                                  
      68               0 :             $foldersDB = (array) $db->get_results(                                                             
      69                 :                 "SELECT courseID, create_time, description, student_write, userID, fileID,                     
      70               0 :                 link, visible_type, name FROM filelist WHERE courseID='".Data::toMysql($_SESSION['course']).   
      71               0 :                 "' AND type='folder' $sqlAdd"                                                                  
      72               0 :             );                                                                                                 
      73               0 :         } else {                                                                                               
      74               0 :             $foldersDB = (array) $db->get_results(                                                             
      75                 :                 "SELECT courseID, create_time, description, student_write, userID, fileID,                     
      76               0 :                 link, visible_type, name FROM filelist WHERE parent_object='".$folderID.                       
      77               0 :                 "' AND courseID='".Data::toMysql($_SESSION['course']).                                         
      78               0 :                 "' AND type='folder' $sqlAdd ORDER BY link"                                                    
      79               0 :             );                                                                                                 
      80                 :         }                                                                                                      
      81               0 :         $folders = array();                                                                                    
      82               0 :         foreach ($foldersDB as $folderDB) {                                                                    
      83               0 :             $folder = $this->getFolderObject($folderDB);                                                       
      84               0 :             $folder->setParentFolder($pFolder);                                                                
      85               0 :             $folder->setFolderState(                                                                           
      86               0 :                 $db->get_var(                                                                                  
      87                 :                     "SELECT userID FROM filetreelayout WHERE userID='".                                        
      88               0 :                     Data::toMysql($_SESSION['userid'])."' AND folderID='".                                     
      89               0 :                     Data::toMysql($folderDB->fileID)."'"                                                       
      90               0 :                 )                                                                                              
      91               0 :             );                                                                                                 
      92               0 :             $folders[] = $folder;                                                                              
      93               0 :         }                                                                                                      
      94               0 :         return $folders;                                                                                       
      95                 :     }                                                                                                          
      96                 :                                                                                                                
      97                 :     public static function saveFolderState($folder) {                                                          
      98               0 :         global $db;                                                                                            
      99               0 :         $folderState = $folder->getFolderState();                                                              
     100               0 :         $userid = Data::toMysql($_SESSION['userid']);                                                          
     101               0 :         $folderID = Data::toMysql($folder->getID());                                                           
     102               0 :         if ($folderState) {                                                                                    
     103               0 :             $db->query("DELETE FROM filetreelayout WHERE userID='".$userid."' AND folderID='".$folderID."'");  
     104               0 :             $folder->setFolderState(false);                                                                    
     105               0 :         } else {                                                                                               
     106               0 :             $db->query("INSERT INTO filetreelayout (userID, folderID) VALUES ('".$userid."','".$folderID."')");
     107               0 :             $folder->setFolderState(true);                                                                     
     108                 :         }                                                                                                      
     109               0 :     }                                                                                                          
     110                 :                                                                                                                
     111                 :     private function getFileObject($dbObject) {                                                                
     112               0 :         $file = new File();                                                                                    
     113               0 :         $file->setFileID($dbObject->fileID);                                                                   
     114               0 :         $file->setVisibleType($dbObject->visible_type);                                                        
     115               0 :         $file->setUserID($dbObject->userID);                                                                   
     116               0 :         $file->setName($dbObject->name);                                                                       
     117               0 :         $file->setOrigFileName($dbObject->orig_filename);                                                      
     118               0 :         $file->setType($dbObject->type);                                                                       
     119               0 :         $file->setLink($dbObject->link);                                                                       
     120               0 :         $file->setSize($dbObject->size);                                                                       
     121               0 :         $file->setCounter($dbObject->counter);                                                                 
     122               0 :         $file->setCreateTime($dbObject->create_time);                                                          
     123               0 :         $file->setDescription($dbObject->description);                                                         
     124               0 :         $file->setExtension($dbObject->extension);                                                             
     125               0 :         $file->setCourseID($dbObject->courseID);                                                               
     126               0 :         $file->setFileManager($this->fileManager);                                                             
     127               0 :         return $file;                                                                                          
     128                 :     }                                                                                                          
     129                 :                                                                                                                
     130                 :     private function getFolderObject($folderDB) {                                                              
     131               0 :         $folder = new Folder($folderDB->fileID);                                                               
     132               0 :         $folder->setCourseID($folderDB->courseID);                                                             
     133               0 :         $folder->setUserID($folderDB->userID);                                                                 
     134               0 :         $folder->setLink($folderDB->link);                                                                     
     135               0 :         $folder->setVisibleType($folderDB->visible_type);                                                      
     136               0 :         $folder->setName($folderDB->name);                                                                     
     137               0 :         $folder->setStudentWrite($folderDB->student_write);                                                    
     138               0 :         $folder->setCreateTime($folderDB->create_time);                                                        
     139               0 :         $folder->setDescription($folderDB->description);                                                       
     140               0 :         $folder->setFileManager($this->fileManager);                                                           
     141               0 :         return $folder;                                                                                        
     142                 :     }                                                                                                          
     143                 :                                                                                                                
     144                 :     public function getFiles($folderID, $sortString = "create_time" , $desc = true) {                          
     145               0 :         global $db;                                                                                            
     146               0 :         $course = Data::toMysql($_SESSION["course"]);                                                          
     147               0 :         $direction = ($desc) ? "DESC" : "ASC";                                                                 
     148               0 :         $sortString = Data::toMysql($sortString);                                                              
     149               0 :         $folderID = Data::toMysql($folderID);                                                                  
     150               0 :         $sqlAdd = self::getVisibilityConstraintSQL();                                                          
     151                 :                                                                                                                
     152               0 :         if ($folderID == 0) {                                                                                  
     153               0 :             $filesDB = (array) $db->get_results(                                                               
     154               0 :                 "SELECT fileID, visible_type, userID, name, orig_filename, type, link, size,                   
     155                 :                 counter, create_time, description, extension, courseID FROM filelist LEFT OUTER                
     156               0 :                 JOIN user ON (filelist.userID=user.ID) WHERE (courseID=$course OR courseID=0)                  
     157               0 :                 AND type!='folder' $sqlAdd "                                                                   
     158               0 :             );                                                                                                 
     159               0 :         } else if ($sortString == "userID") {                                                                  
     160                 :             //ASC sortierung anch NAME damit als 2. Kriteium immer name                                        
     161               0 :             $filesDB = (array) $db->get_results(                                                               
     162                 :                 "SELECT fileID, visible_type, userID, name, orig_filename, type, link, size,                   
     163                 :                 counter, create_time, description, extension, courseID FROM filelist LEFT OUTER                
     164                 :                 JOIN user ON (filelist.userID=user.ID) WHERE parent_object='".                                 
     165               0 :                 $folderID."' AND (courseID=$course OR courseID=0)  AND type!='folder' $sqlAdd ".               
     166               0 :                  " ORDER BY user.Nachname " . $direction  . ", name ASC"                                       
     167               0 :             );                                                                                                 
     168               0 :         } else {                                                                                               
     169                 :             //ASC sortierung anch NAME damit als 2. Kriteium immer name                                        
     170               0 :             $filesDB = (array) $db->get_results(                                                               
     171                 :                 "SELECT fileID, visible_type, userID, name, orig_filename, type, link, size,                   
     172                 :                 counter, create_time, description, extension, courseID FROM filelist WHERE                     
     173               0 :                 parent_object='".$folderID."' AND (courseID='$course' OR courseID=0) AND type!='folder' ".     
     174               0 :                 $sqlAdd." ORDER BY ".$sortString. " ". $direction . ", name ASC"                               
     175               0 :             );                                                                                                 
     176                 :         }                                                                                                      
     177               0 :         $files = array();                                                                                      
     178               0 :         foreach ($filesDB as $fileDB) {                                                                        
     179               0 :             $files[] = self::getFileObject($fileDB);                                                           
     180               0 :         }                                                                                                      
     181               0 :         return $files;                                                                                         
     182                 :     }                                                                                                          
     183                 :                                                                                                                
     184                 :     public function getNewestFiles($limit = 20) {                                                              
     185               0 :         global $db;                                                                                            
     186               0 :         $time = time();                                                                                        
     187               0 :         $course = Data::toMysql($_SESSION["course"]);                                                          
     188               0 :         $limit = Data::toMysql($limit);                                                                        
     189               0 :         $filesDB = (array) $db->get_results(                                                                   
     190               0 :             "SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter,              
     191               0 :             create_time, description, extension, courseID FROM filelist WHERE courseID='$course                
     192               0 :             ' AND visible_type=1 AND type!='folder' AND start_time<'$time' AND end_time>'$time                 
     193               0 :             ' ORDER BY create_time DESC LIMIT $limit"                                                          
     194               0 :         );                                                                                                     
     195               0 :         $files = array();                                                                                      
     196               0 :         foreach ($filesDB as $fileDB) {                                                                        
     197               0 :             $files[] = self::getFileObject($fileDB);                                                           
     198               0 :         }                                                                                                      
     199               0 :         return $files;                                                                                         
     200                 :     }                                                                                                          
     201                 :                                                                                                                
     202                 :     public function getMostRatedFiles($limit = 20) {                                                           
     203               0 :         global $db;                                                                                            
     204               0 :         $time = time();                                                                                        
     205               0 :         $course = Data::toMysql($_SESSION["course"]);                                                          
     206               0 :         $limit = Data::toMysql($limit);                                                                        
     207               0 :         $filesDB = (array) $db->get_results(                                                                   
     208               0 :             "SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter,              
     209               0 :             create_time, description, extension, courseID FROM filelist WHERE courseID='$course                
     210               0 :             ' AND visible_type=1 AND type!='folder' AND start_time<'$time' AND end_time>'$time                 
     211               0 :             ' ORDER BY counter DESC LIMIT $limit"                                                              
     212               0 :         );                                                                                                     
     213               0 :         $files = array();                                                                                      
     214               0 :         foreach ($filesDB as $fileDB) {                                                                        
     215               0 :             $files[] = self::getFileObject($fileDB);                                                           
     216               0 :         }                                                                                                      
     217               0 :         return $files;                                                                                         
     218                 :     }                                                                                                          
     219                 :                                                                                                                
     220                 :     public function getFileByID($fileID) {                                                                     
     221               0 :         global $db;                                                                                            
     222               0 :         $fileID = Data::toMysql($fileID);                                                                      
     223               0 :         $fileDB = $db->get_row(                                                                                
     224               0 :             "SELECT fileID, visible_type, userID, name, orig_filename, type, link, size, counter,              
     225               0 :             create_time, description, extension, courseID FROM filelist WHERE fileID = '$fileID                
     226               0 :             ' AND type='file'"                                                                                 
     227               0 :         );                                                                                                     
     228               0 :         if ($fileDB) {                                                                                         
     229               0 :             return $this->getFileObject($fileDB);                                                              
     230                 :         }                                                                                                      
     231               0 :         return false;                                                                                          
     232                 :     }                                                                                                          
     233                 :                                                                                                                
     234                 :                                                                                                                
     235                 :     public function getFolderByID($folderID) {                                                                 
     236               0 :         global $db;                                                                                            
     237               0 :         $folderID = Data::toMysql($folderID);                                                                  
     238               0 :         $folderDB = $db->get_row(                                                                              
     239                 :             "SELECT name, fileID, courseID, link, userID, student_write, create_time, description,             
     240               0 :             visible_type FROM filelist WHERE type='folder' AND fileID='".$folderID."'"                         
     241               0 :         );                                                                                                     
     242               0 :         if ($folderDB) {                                                                                       
     243               0 :             return $this->getFolderObject($folderDB);                                                          
     244                 :         }                                                                                                      
     245               0 :         return false;                                                                                          
     246                 :     }                                                                                                          
     247                 :                                                                                                                
     248                 :     public function getUserCourses($userID) {                                                                  
     249               0 :         global $settings, $db;                                                                                 
     250               0 :         $userID = Data::toMysql($userID);                                                                      
     251               0 :         $courseID = Data::toMysql($_SESSION['course']);                                                        
     252               0 :         if ($_SESSION['usergroup'] == ADMIN                                                                    
     253               0 :         || $_SESSION['usergroup'] == SEKRETARIAT) {                                                            
     254                 :             $sql = "SELECT c.ID, c.ShortName AS SN, u.ShortName FROM courses AS c                              
     255                 :                 RIGHT JOIN user_course AS uc ON c.ID = uc.courseID LEFT JOIN user AS u                         
     256                 :                 ON uc.userID = u.ID WHERE ((u.Usergroup = 3 AND uc.differentUsergroup = 0)                     
     257               0 :                 OR uc.differentUsergroup = 3) AND c.closed = 0 " . "AND c.ID <> ". $courseID .                 
     258               0 :                 " ORDER BY c.ShortName, c.ID";                                                                 
     259               0 :         } else {                                                                                               
     260                 :             $sql = "SELECT c.ID, c.ShortName AS SN, u.ShortName FROM (user_course AS uc1,                      
     261                 :             user AS u) RIGHT JOIN user_course AS uc2 ON uc1.courseID = uc2.courseID RIGHT                      
     262                 :             JOIN courses AS c ON uc1.courseID = c.ID WHERE ((u.Usergroup = 3 AND                               
     263                 :             uc2.differentUsergroup = 0) OR uc2.differentUsergroup = 3) AND uc1.userID  = ".                    
     264               0 :             $userID." AND u.ID = uc2.userID AND c.closed    = 0 " . "AND c.ID <> ". $courseID .                
     265               0 :             " ORDER BY c.ShortName, c.ID";                                                                     
     266                 :         }                                                                                                      
     267               0 :         $courses = (array) $db->get_results($sql);                                                             
     268                 :                                                                                                                
     269               0 :         return $courses;                                                                                       
     270                 :     }                                                                                                          
     271                 :                                                                                                                
     272                 :     public function countSubElements($folderID, $subFolders = true) {                                          
     273               0 :         global $db;                                                                                            
     274               0 :         $count = 0;                                                                                            
     275               0 :         $folderID = Data::toMysql($folderID);                                                                  
     276               0 :         $sqlAdd = self::getVisibilityConstraintSQL();                                                          
     277               0 :         if ($subFolders) {                                                                                     
     278               0 :             $folders = $db->get_col(                                                                           
     279                 :                 "SELECT fileID FROM filelist WHERE type='folder' AND parent_object='".                         
     280               0 :                 $folderID."' ".$sqlAdd                                                                         
     281               0 :             );                                                                                                 
     282               0 :             if ($folders) foreach($folders as $folder) {                                                       
     283               0 :                 $count+= $this->countSubElements($folder);                                                     
     284               0 :             }                                                                                                  
     285               0 :         }                                                                                                      
     286                 :         $count+=                                                                                               
     287               0 :             $db->get_var(                                                                                      
     288                 :                 "SELECT COUNT(*) FROM filelist WHERE                                                           
     289                 :                 type!='folder' AND parent_object='".                                                           
     290               0 :                 $folderID."' ".                                                                                
     291                 :                 $sqlAdd                                                                                        
     292               0 :                );                                                                                              
     293               0 :         return $count;                                                                                         
     294                 :     }                                                                                                          
     295                 :                                                                                                                
     296                 :     /**                                                                                                        
     297                 :      * Get short course name.                                                                                  
     298                 :      *                                                                                                         
     299                 :      * @param Integer $courseID Course id                                                                      
     300                 :      * @return String Short course name                                                                        
     301                 :      */                                                                                                        
     302                 :     public function getCourseShortNameByID($courseID) {                                                        
     303               0 :         global $db;                                                                                            
     304               0 :         $courseID = Data::toMysql($courseID);                                                                  
     305               0 :         return $db->get_var("SELECT `ShortName` FROM `courses` WHERE `ID` = $courseID");                       
     306                 :     }                                                                                                          
     307                 :                                                                                                                
     308                 :     /**                                                                                                        
     309                 :      * Log file download.                                                                                      
     310                 :      * Write log entry to filelog table and increment download count in filelist table.                        
     311                 :      *                                                                                                         
     312                 :      * @param Integer $resourceID Resource id                                                                  
     313                 :      */                                                                                                        
     314                 :     public function logResourceDownload($resourceID) {                                                         
     315               0 :         global $db;                                                                                            
     316               0 :         $time = Data::toMysql(time());                                                                         
     317               0 :         $resourceID = Data::toMysql($resourceID);                                                              
     318               0 :         $db->query(                                                                                            
     319               0 :             "INSERT INTO filelog (userID, fileID, date) VALUES ('".$_SESSION['userid'].                        
     320               0 :             "','$resourceID','$time')"                                                                         
     321               0 :         );                                                                                                     
     322               0 :         $db->query("UPDATE filelist SET counter=counter+1 WHERE fileID='$resourceID'");                        
     323               0 :     }                                                                                                          
     324                 : }                                                                                                              

Generated by PHPUnit 3.2.21 and Xdebug 2.0.3 at Thu Nov 26 17:01:15 CET 2009.